
from langgraph.graph import StateGraph
from langgraph.prebuilt import ToolNode
from langgraph.graph import END
from langgraph.checkpoint.memory import MemorySaver

from core.state import AgentState
from core.nodes import compress_node, agent_node, condition_node
from core.tools import tools


workflow = StateGraph(AgentState)

workflow.add_node("compress", compress_node)
workflow.add_node("agent", agent_node)
workflow.add_node("tools", ToolNode(tools))

workflow.set_entry_point("compress")
workflow.add_edge("compress", "agent")

workflow.add_conditional_edges(
    source = "agent",
    path = condition_node,
    path_map = {"tools": "tools", END: END}
)
workflow.add_edge("tools", "compress")

memory = MemorySaver()
workflow = workflow.compile(checkpointer=memory)